﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ControlTask3
{
    class Vector
    {
        private int[] vectorArray;
        private int lenght;
        private int shift;

        public Vector(int arrayLenght, int shift)
        {
            this.shift = shift;
            Lenght = arrayLenght;
            vectorArray = new int[Lenght];
            for (int i = 0; i < vectorArray.Length; i++)
            {
                vectorArray[i] = i;
            }
        }

        public Vector(int arrayLenght)
        {
            Lenght = arrayLenght;
            vectorArray = new int[Lenght];
            for (int i = 0; i < vectorArray.Length; i++)
            {
                vectorArray[i] = i;
            }
        }

        public int Lenght
        {
            get { return lenght; }
            set { lenght = value; }
        }

        public int AiExample { get; set; }

        public int this[int index]
        {
            get { return vectorArray[index]; }
            set                                     // контроль выхода за пределы массива
            {
                if (value < 0)
                {
                    vectorArray[index] = 0;
                }
                if (value > vectorArray.Length)
                {
                    int last = vectorArray.Length - 1;
                    value = vectorArray[last];
                }
                else
                {
                    vectorArray[index] = value;
                }
            }
        }

        public int GetByIndex(int index)            //получение элемента по индексу
        {
            return vectorArray[index];
        }

        public void SetByIndex(int index, int value)  // обращение к конкретному элементу
        {
            vectorArray[index] = value;
        }

        public Vector Addition(Vector array)
        {
            if (Lenght == array.Lenght)
            {
                Vector resultArr = new Vector(Lenght);
                for (int i = 0; i < Lenght; i++)
                {
                    resultArr.SetByIndex(i, array.GetByIndex(i) + this.GetByIndex(i));
                }
                return resultArr;
            }
            else
            {
                Console.WriteLine("Arrays have different length");
                return new Vector(0);
            }
        }

        public Vector Subtraction(Vector array)
        {
            if (Lenght == array.Lenght)
            {
                Vector resultArr = new Vector(Lenght);
                for (int i = 0; i < Lenght; i++)
                {
                    resultArr.SetByIndex(i, array.GetByIndex(i) - this.GetByIndex(i));
                }
                return resultArr;
            }
            else
            {
                Console.WriteLine("Arrays have different length");
                return new Vector(0);
            }
        }

        public void PrintArr()
        {
            foreach (int value in vectorArray)
            {
                Console.WriteLine("{0}: {1}", Array.IndexOf(vectorArray, value), value);
            }
        }

    }
}
